<?php

namespace backend\modules\groups\models\query;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\modules\groups\models\Useringroups;

/**
 * UseringroupsSearch represents the model behind the search form about `app\modules\groups\models\Useringroups`.
 */
class UseringroupsSearch extends Useringroups
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['userGroupID', 'user_id', 'groupID', 'isLeader', 'isVirtualGroupUser'], 'integer'],
            [['managerGroup'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = Useringroups::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $query->andFilterWhere([
            'userGroupID' => $this->userGroupID,
            'user_id' => $this->user_id,
            'groupID' => $this->groupID,
            'isLeader' => $this->isLeader,
            'isVirtualGroupUser' => $this->isVirtualGroupUser,
        ]);

        $query->andFilterWhere(['like', 'managerGroup', $this->managerGroup]);

        return $dataProvider;
    }
}
